package com.cci.kangdao.task;

import com.cci.kangdao.common.RedisKeys;
import com.cci.kangdao.common.type.OverTimeType;
import com.cci.kangdao.crmapi.CRMApiUtils;
import com.cci.kangdao.crmapi.CRMResponeEntity;
import com.cci.kangdao.crmapi.CRMServiceApi;
import com.cci.kangdao.dao.*;
import com.cci.kangdao.dao.model.*;
import com.cci.kangdao.redis.RedisClientUtils;
import com.cci.kangdao.service.NoticeService;
import com.cci.kangdao.service.RemindTaskService;
import com.cci.kangdao.service.impl.CRMPlatformServiceImpl;
import com.cci.kangdao.service.impl.WorkOrderTServiceImpl;
import com.cci.kangdao.utilTool.LocalTimeUtil;
import com.cci.kangdao.utilTool.PropertiesUtil;
import com.cci.kangdao.utilTool.SmsUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

@Component
public class RemindTask {
	private Logger log = Logger.getLogger(this.getClass().getName());
	@Autowired
	public RemindTaskService remindTaskService;
	@Autowired
	private RedisClientUtils redisClientUtils;
	@Autowired
	private LoginDao loginDao;
	@Autowired
	private PositionUserTDao positionUserTDao;
	@Autowired
	private WorkOrderTDao workOrderTDao;
	@Autowired
	private UserTDao userTDao;
	@Autowired
	private WorkOrderTServiceImpl workOrderTServiceImpl;
	@Autowired
	private WorkOrderRepairDao workOrderRepairDao;
    @Autowired
    private CRMPlatformServiceImpl cRMPlatformServiceImpl;
    @Resource
	private CRMServiceApi crmServiceApi;
	@Resource
	private CRMPlatformServiceDao platformServiceDao;
	@Autowired
	private CompanyTDao companyTDao;
	@Autowired
	private AllServiceStationDao allServiceStationDao;
	@Resource
	private NoticeService noticeService;
	@Resource
	private ServiceStationDao serviceStationDao;
	@Resource
	private EngineMsgDao engineMsgDao;
	@Resource
	private OrderManageDao orderManageDao;

	private String msgbodyCCEC1 = "您有新工单信息，工单号%s，请尽快处理。";
	private String msgbodyCCEC2 = "您有新的工单待指派，工单号%s，请尽快处理。";
	private String msgbodyCCEC3 = "您有新的工单信息待处理，工单号%s，请查看。";
	private String msgbodyCCEC4 = "您有工单未出发，工单号%s，工单已超时，请尽快处理。";
	private String msgbodyCCEC5 = "您有工单待400审核，工单号%s，请尽快处理。";
	private String msgbodyCCEC6 = "您有工单待回访，工单号%s，请处理。";
	private String msgbodyCCEC7 = "您有工单待审核，工单号%s，请处理。";
	private String msgbodyCCEC8 = "您有工单未完成，工单号%s，工单已超过24小时，请尽快处理";
	private String msgbodyCCEC9 = "您有未处理工单，工单号%s，工单已超24小时，请尽快处理。";
	//xcec2.4.0补充话术
    private String xcecAddWordsArt ="服务站名称:%s，客户姓名:%s，发动机号:%s，发动机故障描述:%s，工单处理时长:%s";
	// sprint18：新增以下短信发送：
	// 1）区域经理接收7小时预警提醒短信，①短信模板：7小时预警提醒：XX服务商，现有维修工单将超时，请尽快处理 ②发送机制：服务总时长大于等于7小时实时发送，服务总时长=技师完成维修时间-工单创建时间；
	// 2）区域经理接收重大故障提醒短信，①短信模板：重大故障提醒：XXX服务商，,发动机号XXX，现有重大故障工单，请尽快处理 ②发送机制：技师接单点开始维修选择故障级别，如果选择是重大故障提交后短信实时提醒。
	private String xcecSevenHourStr ="7小时预警提醒：%s服务商，现有维修工单将超时，请尽快处理。";
	//XCEC有以下逻辑: sprint18
	//区域经理接收服务商超30分钟未接单短信提醒：
	//修改：①待服务商接单时间大于等于30分钟发送超时提醒改为20分钟；②短信模板修改为：服务延迟提醒：XXX服务商，工单号XXX，现有工单未接，请尽快处理。
	private String xcecMsgBody ="服务延迟提醒：%s服务商，工单号%s，现有工单未接，请尽快处理。";
	// sprint18外出审批消息格式更新
	private String xcecOverTimeBody = "外出审批提醒：%s服务商，工单号%s，外出里程%skm，请尽快审批。";

	//服务工单所有的定时重传
    public void workOrderExceptionSynchronization(){
		try {
			log.info("重试服务工单异常队列-开始");
			boolean workOrderIsSync = true;
			String isSync = redisClientUtils.get("workOrderIsSync");
			if(StringUtils.isNotBlank(isSync)){
				workOrderIsSync = false;
			}
			cRMPlatformServiceImpl.syncExceptionalOrderInfoToCRM(workOrderIsSync);
			log.info("重试服务工单异常队列-结束");
		} catch (Exception e) {
			log.error("重试服务工单异常队列发生异常，异常信息"+e.getMessage(),e);
		}

		try {
			log.info("重试CCEC服务工单异常队列-开始");
			crmServiceApi.retryExceptionSync();
			log.info("重试CCEC服务工单异常队列-结束");
		} catch (Exception e) {
			log.error("重试CCEC服务工单异常队列发生异常，异常信息"+e.getMessage(),e);
		}
    }

	//超时各角色超时工单提醒      一分钟执行一次
    public void taskCycle() {
		log.info("超时工单定时任务--开始");
		String systime = LocalTimeUtil.getRealCurrentTime();
		try {
			//1、服务商超时未接单   DCEC和DBU,xcec共用
			getAssignStationTimeList(systime);
		} catch (Exception e) {
			log.error("服务商超时未接单,DCEC,DBU,XCEC共用发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//2.服务技师超时未接单  DCEC和DBU,xcec共用
			getAssignEngineerimeList(systime);
		} catch (Exception e) {
			log.error("服务技师超时未接单,DCEC,DBU,XCEC共用发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//3.服务技师接单超时未出发   dcec,xcec共用
			getReceiveTimeEngineerList(systime);
		} catch (Exception e) {
			log.error("服务技师接单超时未出发,DCEC,XCEC，异常信息"+e.getMessage(),e);
		}
		try {
			//4.未完成工单超时提醒    dcec,xcec,ccec共用
			getSuccessWorkOrder(systime);
		} catch (Exception e) {
			log.error("未完成工单超时提醒,DCEC,XCEC,CCEC共用发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//5.区域服务经理新工单超时未确认提醒(包括区域经理接收外出审批单提醒)   dcec,xcec共用
			getNewWorkOrderList(systime);
		} catch (Exception e) {
			log.error("区域服务经理新工单超时未确认提醒,DCEC,XCEC共用发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//6.DBU区域工程师超时未处理工单   超时提醒
			areaEngineerOverTimeUnDealRemind(systime);
		} catch (Exception e) {
			log.error("DBU区域工程师超时未处理工单发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//7.待用户评价工单超时2小时(xcec)和24小时(其他渠道)，超时半小时(ccec  待用户评价-400远程解决)未评价自动变为服务完成工单
			//ccec待用户评价超时半小时未评价  工单状态转为待400回访
			getWaitUserEvaluateWorkOrderList(systime);
		} catch (Exception e) {
			log.error("待用户评价工单超时发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//8.获取ccec400审核不通过   待更新的工单列表  根据工单来源提醒对应用户或者服务商更新工单信息，超时10/20/30分钟提醒用户或者服务商更新工单信息
			//超时40分钟工单自动变为待400审核-400回访/诊断中/继续服务
			getToBeUpdatedWorkOrderList(systime);
		} catch (Exception e) {
			log.error("获取ccec400审核不通过,超时待更新的工单发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//9.获取ccec待400审核-工单已创建     待400审核-400回访/诊断中/继续服务/待更新    待400回访    待400主管审核的工单信息
			getCCECWaitFZZAuditAndVisitAndWaitFZZZGAudit(systime);
		} catch (Exception e) {
			log.error("获取ccec待400审核-工单已创建,待400主管审核的工单信息发生异常，异常信息"+e.getMessage(),e);
		}
		try {
			//10.获取ccec待服务商接单     待派服务技师    待服务技师接单   技师已接单状态下所有工单    然后根据工单获取推送的用户
			getCCECServiceStationOverTimeWorkOrder(systime);
		} catch (Exception e) {
			log.error("获取ccec待服务商接单发生异常，异常信息"+e.getMessage(),e);
		}
		log.info("超时工单定时任务--结束");
    }

	@Transactional
	public List<Map<String,Object>> getCCECServiceStationOverTimeWorkOrder(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		//查询出对应的工单信息
		List<Map<String,Object>> list = remindTaskService.getCCECServiceStationOverTimeWorkOrder(params);
		if(CollectionUtils.isNotEmpty(list)){
			for(Map<String,Object> ccecServiceStationOverTimeWorkOrder : list){
				long orderId = MapUtils.getLongValue(ccecServiceStationOverTimeWorkOrder,"OrderId");
				long serviceStationId = MapUtils.getLongValue(ccecServiceStationOverTimeWorkOrder,"ServiceStationId",0);
				String orderNo = MapUtils.getString(ccecServiceStationOverTimeWorkOrder,"OrderNo","");
				int overTime = MapUtils.getIntValue(ccecServiceStationOverTimeWorkOrder,"OverTime");
				String ccssOrderNo = MapUtils.getString(ccecServiceStationOverTimeWorkOrder,"CCSSOrderNo","");
				int orderStatus = MapUtils.getIntValue(ccecServiceStationOverTimeWorkOrder,"OrderStatus");
				if(overTime == 10 || overTime == 20 || overTime == 30){
					if(orderStatus == 4 || orderStatus == 6){    //待服务商接单    待派服务技师    推送站长信息员
						List<UserT> zzXXYList = userTDao.getStationMasterListByServiceStationId(serviceStationId);
						if(CollectionUtils.isNotEmpty(zzXXYList)){
							for(UserT userT : zzXXYList){
								if(orderStatus == 4){
									sendMsgCCEC(userT.getPhone(), orderNo, userT.getUserName(), String.valueOf(orderId), String.valueOf(userT.getId()), 7, 2,1,ccssOrderNo);
								}else{
									sendMsgCCEC(userT.getPhone(), orderNo, userT.getUserName(), String.valueOf(orderId), String.valueOf(userT.getId()), 7, 2,2,ccssOrderNo);
								}
							}
						}
					}else{   //待服务技师接单       外出工单  技师已接单   未出发    推送主技师
						List<UserT> zJSList = userTDao.getJSUserListByOrderStatus(orderId,1);
						if(CollectionUtils.isNotEmpty(zJSList)){
							for(UserT userT : zJSList){
								if(orderStatus == 7){
									sendMsgCCEC(userT.getPhone(), orderNo, userT.getUserName(), String.valueOf(orderId), String.valueOf(userT.getId()), 7, 2,3,ccssOrderNo);
								}else{
									sendMsgCCEC(userT.getPhone(), orderNo, userT.getUserName(), String.valueOf(orderId), String.valueOf(userT.getId()), 7, 2,4,ccssOrderNo);
								}
							}
						}
					}
				}
			}
		}

		return list;
	}




    //获取ccec待400审核-工单已创建     待400审核-400回访/诊断中/继续服务/待更新    待400回访的工单信息
	/*23状态下肯定不会绑定旧工单加上24状态下没有绑定旧工单的数据
	拼接上
	24状态下只绑定了旧工单的数据
	拼接上
	待400回访工单
	上面都是根据是否有服务站id   去推相应的400
	拼接上
	待400主管审核工单
	推所有的400主管*/
	@Transactional
	public List<Map<String,Object>> getCCECWaitFZZAuditAndVisitAndWaitFZZZGAudit(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		//查询出对应的工单信息
		List<Map<String,Object>> list = remindTaskService.getCCECWaitFZZAuditAndVisitAndWaitFZZZGAudit(params);
		//获取ccec所有的400
		List<Map<String,Object>> allAreaManagerMap = workOrderRepairDao.getCCECAreaManager(109);
		if(CollectionUtils.isNotEmpty(list)){
			for(Map<String,Object> ccecWaitFZZAudit : list){
				long orderId = MapUtils.getLongValue(ccecWaitFZZAudit,"OrderId");
				long serviceStationId = MapUtils.getLongValue(ccecWaitFZZAudit,"ServiceStationId",0);
				String orderNo = MapUtils.getString(ccecWaitFZZAudit,"OrderNo","");
				int overTime = MapUtils.getIntValue(ccecWaitFZZAudit,"OverTime");
				String ccssOrderNo = MapUtils.getString(ccecWaitFZZAudit,"CCSSOrderNo","");
				int orderStatus = MapUtils.getIntValue(ccecWaitFZZAudit,"OrderStatus");
				if(overTime == 10 || overTime == 20 || overTime == 30){
					if(orderStatus == 33){   //33	待400主管审核    直接推送所有的400主管
						//获取ccec所有的400主管
						List<UserT> orderManageList = orderManageDao.getManagerList();
						if(CollectionUtils.isNotEmpty(orderManageList)){
							for(UserT orderManage: orderManageList) {
								sendMsgCCEC(orderManage.getPhone(), orderNo, orderManage.getUserName(), String.valueOf(orderId), String.valueOf(orderManage.getId()), 7, 2,7,ccssOrderNo);
							}
						}
					}else{    //23,24,32走下面的逻辑
						if(serviceStationId == 0){   //未指派服务站    找到ccec渠道所有的400
							if(CollectionUtils.isNotEmpty(allAreaManagerMap)){
								for(int i=0;i<allAreaManagerMap.size();i++){
									Map<String,Object> managerMap = allAreaManagerMap.get(i);
									String userPhone = managerMap.get("phone")+"";
									String UserName = managerMap.get("UserName")+"";
									String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
									if(orderStatus == 32){   //待400回访  32
										sendMsgCCEC(userPhone, orderNo, UserName, String.valueOf(orderId), UserID, 7, 2,6,ccssOrderNo);
									}else{    //待400审核  23  24
										sendMsgCCEC(userPhone, orderNo, UserName, String.valueOf(orderId), UserID, 7, 2,5,ccssOrderNo);
									}
								}
							}
						}else{  //指派了服务站   获取该服务站的400
							List<Map<String,Object>> managerList = remindTaskService.getRegionalServiceManager(String.valueOf(serviceStationId),109);
							if(null!=managerList&&managerList.size()>0){
								for(int i=0;i<managerList.size();i++){
									Map<String,Object> managerMap = managerList.get(i);
									String userPhone = managerMap.get("UserPhone")+"";
									String UserName = managerMap.get("UserName")+"";
									String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
									if(orderStatus == 32){   //待400回访  32
										sendMsgCCEC(userPhone, orderNo, UserName, String.valueOf(orderId), UserID, 7, 2,6,ccssOrderNo);
									}else{    //待400审核  23  24
										sendMsgCCEC(userPhone, orderNo, UserName, String.valueOf(orderId), UserID, 7, 2,5,ccssOrderNo);
									}
								}
							}
						}
					}
				}
			}
		}
		return list;
	}


	
	/**
	 * 区域服务经理新工单超时未确认提醒
	 *  
	 * @return
	 */
	@Transactional
	public List<Map<String,Object>> getNewWorkOrderList(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus2").trim());
		//查询出对应的工单信息
		List<Map<String,Object>> list = remindTaskService.getNewWorkOrderList(params);
		if(null!=list&&list.size()>0){
			for(int i=0;i<list.size();i++){
				Map<String,Object> map  = list.get(i);
				//区域服务经理超时未确认工单
				NewWorkOrderList(map);
			}
		}
		return list;
	}
	
	/**
	 * 服务商未接单
	 * 1、工单状态为待服务商接单
	 * 2、开始时间为指派服务站时间
	 * @return
	 */
	@Transactional
	public List<Map<String,Object>> getAssignStationTimeList(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus4").trim());
		//因为服务商超时未接单时    一条工单信息会推送给信息员和站长    所以下面的集合保存不重复的工单信息    
		List<Map<String, Object>> distinctOrderIdOederNoMapList = new ArrayList<Map<String,Object>>();
		//查询出DCEC和DBU,XCEC所有待服务商接单的工单信息
		List<Map<String,Object>> list = remindTaskService.getAssignStationTimeList(params);
		if(null!=list&&list.size()>0){  
			for(int i=0;i<list.size();i++){
				Map<String,Object> map  = list.get(i);
				//服务商超时未接单处理   给服务站站长和信息员消息推送
				ServerStationOverTime(map);
				//当前工单服务渠道
				long orderChannel = Long.parseLong(map.get("OrderChannel").toString());
				//DBU只在服务商五分钟未接单推送消息   所以DBU没有以下逻辑；sprint17改为DBU只在服务商十分钟未接单推送消息
				//DCEC有以下逻辑
				if( orderChannel == 3){
					//间隔时长
					String OverTime = map.get("OverTime")+"";
					//工单号
					String OrderNo = map.get("OrderNo")+"";
					//工单ID
					String OrderId = map.get("OrderId")+"";

					//服务站ID
					String ServiceStationId = map.get("ServiceStationId")+"";
					if(OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())){
						Map<String,Object> distinctOrderIdOederNoMap  = new HashMap<String, Object>();
						distinctOrderIdOederNoMap.put("orderChannel",orderChannel);
						distinctOrderIdOederNoMap.put("OrderNo",OrderNo);
						distinctOrderIdOederNoMap.put("OrderId",OrderId);
						distinctOrderIdOederNoMap.put("ServiceStationId",ServiceStationId);
						if(!distinctOrderIdOederNoMapList.contains(distinctOrderIdOederNoMap)) {
							distinctOrderIdOederNoMapList.add(distinctOrderIdOederNoMap);   //集合添加超时15分钟并且不重复的工单信息
						}
					}
				}
				//XCEC有以下逻辑: sprint18
				//区域经理接收服务商超30分钟未接单短信提醒：
				// 修改：①待服务商接单时间大于等于30分钟发送超时提醒改为20分钟；②短信模板修改为：服务延迟提醒：XXX服务商，工单号XXX，现有工单未接，请尽快处理。
				if(orderChannel == 4){
					//间隔时长
					String OverTime = map.get("OverTime")+"";
					//工单号
					String OrderNo = map.get("OrderNo")+"";
					//工单ID
					String OrderId = map.get("OrderId")+"";
					//服务站ID
					String ServiceStationId = map.get("ServiceStationId")+"";
					if(OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyMinutes").trim())){
						Integer IsTechSupport = MapUtils.getInteger(map, "IsTechSupport",0);
						Map<String,Object> distinctOrderIdOederNoMap  = new HashMap<String, Object>();
						distinctOrderIdOederNoMap.put("IsTechSupport",IsTechSupport);
						distinctOrderIdOederNoMap.put("orderChannel",orderChannel);
						distinctOrderIdOederNoMap.put("OrderNo",OrderNo);
						distinctOrderIdOederNoMap.put("OrderId",OrderId);
						distinctOrderIdOederNoMap.put("ServiceStationId",ServiceStationId);
						distinctOrderIdOederNoMap.put("StationName",MapUtils.getString(map,"StationName",""));
						distinctOrderIdOederNoMap.put("CustomerName",MapUtils.getString(map,"CustomerName",""));
						distinctOrderIdOederNoMap.put("ESN",MapUtils.getString(map,"ESN",""));
						distinctOrderIdOederNoMap.put("CustomerComplaint",MapUtils.getString(map,"CustomerComplaint",""));
						distinctOrderIdOederNoMap.put("CreateTime",MapUtils.getString(map,"CreateTime",""));
						if(!distinctOrderIdOederNoMapList.contains(distinctOrderIdOederNoMap)) {
							distinctOrderIdOederNoMapList.add(distinctOrderIdOederNoMap);   //集合添加超时15分钟并且不重复的工单信息
						}
					}
				}
			}
		}

		//服务经理消息推送
		for(Map<String, Object> m :distinctOrderIdOederNoMapList) {
			//工单号
			String OrderNo = m.get("OrderNo")+"";
			//工单ID
			String OrderId = m.get("OrderId")+"";
			//服务渠道
			int wotChannel = MapUtils.getIntValue(m,"orderChannel");
			//服务站ID
			String ServiceStationId = m.get("ServiceStationId")+"";
			Integer isTechSupport = MapUtils.getInteger(m, "IsTechSupport",0);
			List<Map<String,Object>> managerList = new ArrayList<>();
			if(1==isTechSupport){
				managerList =  remindTaskService.getManager(ServiceStationId,wotChannel);
			}else {
				managerList =  remindTaskService.getRegionalServiceManager(ServiceStationId,wotChannel);
			}

			if(null!=managerList&&managerList.size()>0){
				for(int i=0;i<managerList.size();i++){
					Map<String,Object> managerMap = managerList.get(i);
					String userPhone = managerMap.get("UserPhone")+"";
					String UserName = managerMap.get("UserName")+"";
					String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
					if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
						//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
						String stationName = MapUtils.getString(m,"StationName","");
						String customerName = MapUtils.getString(m,"CustomerName","");
						String eSN = MapUtils.getString(m,"ESN","");
						String customerComplaint = MapUtils.getString(m,"CustomerComplaint","");
						String createTime = MapUtils.getString(m,"CreateTime","");
						long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,systime);
						String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
						// sprint18需求：新的短信模板
						String xcecAddWordsArtStr = String.format(xcecMsgBody, stationName,OrderNo);
						sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 25, 2,xcecAddWordsArtStr);
					}else{  //其他渠道走之前推送公共方法
						sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
					}
				}
			}
		}

		return list;
	}
	
	/**
	 * 服务技师未接单
	 * 1、工单状态为待服务技师接单
	 * 2、开始时间为指派服务技师时间
	 * @return
	 */
	@Transactional
	public void getAssignEngineerimeList(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus7").trim());
		//查询出对应的工单信息
		//获取服务技师
		//去重的集合
		Set<String> set = new HashSet<>();
		List<Map<String,Object>> list1 = remindTaskService.getAssignEngineerimeList1(params);
		if(null!=list1&&list1.size()>0){
			for(int i=0;i<list1.size();i++){
				Map<String,Object> map  = list1.get(i);
				String orderNo = MapUtils.getString(map, "OrderNo", "");
				String Phone = MapUtils.getString(map, "Phone", "");
				set.add(orderNo + Phone);
				//服务技师超时未接单处理
				ServiceStationTechnicianOverTime(map);
			}
		}


        //获取服务站站长和信息员
        List<Map<String,Object>> list2 = remindTaskService.getAssignEngineerimeList2(params);
		if(null!=list2&&list2.size()>0){
			for(int i=0;i<list2.size();i++){
				Map<String,Object> map  = list2.get(i);
				String orderNo = MapUtils.getString(map, "OrderNo", "");
				String Phone = MapUtils.getString(map, "Phone", "");
				//将已经发送的过滤掉
				if (set.contains(orderNo + Phone)) {
					continue;
				}
				//服务技师超时未接单处理
				ServiceStationTechnicianOverTime(map);
			}
		}
		/**
		 * 1、通过指定工单状态，查询相应工单的服务站然后获取服务站的服务经理
		 */
		//获取所有工单状态为服务技师未接单和未接单间隔时间
		List<Map<String, Object>> workOrderTMaps = workOrderTDao.getAssignEngineerTimeWorkOrderTByOrderStatus(params);
		List<Map<String, Object>> newWorkOrderTMaps = new ArrayList<Map<String,Object>>();
		if(workOrderTMaps.size() !=0) {
			for(Map<String, Object> workOrderTMap : workOrderTMaps) {
				String OverTime = workOrderTMap.get("OverTime").toString();
				String FifteenMinutes = PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim();
				if(OverTime.equals(FifteenMinutes)) {
					newWorkOrderTMaps.add(workOrderTMap);
				}	
			}
		}
		if(newWorkOrderTMaps.size() != 0) {
			for(Map<String, Object> workOrderTMap : newWorkOrderTMaps) {
				//工单号
				String OrderNo = workOrderTMap.get("OrderNo")+"";
				//工单ID
				String OrderId = workOrderTMap.get("ID")+"";
				Map<String, Object> serviceStationIdMap = new HashMap<String, Object>();
				serviceStationIdMap.put("ServiceStationID", Long.parseLong(String.valueOf(workOrderTMap.get("ServiceStationId"))));
				long orderChannel = MapUtils.getLongValue(workOrderTMap,"OrderChannel");
				serviceStationIdMap.put("CompanyID", orderChannel);
				Integer isTechSupport = MapUtils.getInteger(workOrderTMap, "IsTechSupport",0);
				List<PositionUserT> positionUserTList = new ArrayList<>();
				if(1==isTechSupport){
					positionUserTList =  positionUserTDao.getManager(serviceStationIdMap);
				}else {
					positionUserTList =   positionUserTDao.getPostUserTListByServiceStationIdCompanyId(serviceStationIdMap);
				}
				//获取对应服务站服务经理
				if(positionUserTList.size()!=0) {
					for(PositionUserT positionUserT : positionUserTList) {
						String userPhone = positionUserT.getUserPhone();
						String UserName = loginDao.getUserByPhone(userPhone).get(0).getUserName();
						String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
						if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
							//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
							String stationName = MapUtils.getString(workOrderTMap,"StationName","");
							String customerName = MapUtils.getString(workOrderTMap,"CustomerName","");
							String eSN = MapUtils.getString(workOrderTMap,"ESN","");
							String customerComplaint = MapUtils.getString(workOrderTMap,"CustomerComplaint","");
							String createTime = MapUtils.getString(workOrderTMap,"CreateTime","");
							long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,systime);
							String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
							String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
							sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr);
						}else{
							sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
						}
					}
				}
			}
		}

	}
	
	
	/**
	 * 服务技师接单未出发
	 * 1、工单状态为技师已接单
	 * 2、开始时间为服务技师接单时间
	 * @return
	 */
	@Transactional
	public void getReceiveTimeEngineerList(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus8").trim());
		//查询出对应的工单信息
		//获取服务技师
		List<Map<String,Object>> list1 = remindTaskService.getReceiveTimeEngineerList1(params);
		//获取服务站站长和信息员
		List<Map<String,Object>> list2 = remindTaskService.getReceiveTimeEngineerList2(params);
		Set<String> set = new HashSet<>();
		if(null!=list1&&list1.size()>0){
			for(int i=0;i<list1.size();i++){
				Map<String,Object> map  = list1.get(i);
				//服务技师接单未出发
				String phone = (String) map.get("Phone");
				String OrderNo = (String) map.get("OrderNo");
				set.add(OrderNo + phone);
				ReceiveTimeEngineerOverTime(map);
			}
		}
		if(null!=list2&&list2.size()>0){
			for(int i=0;i<list2.size();i++){
				Map<String,Object> map  = list2.get(i);
				//服务技师接单未出发
				String phone = (String) map.get("Phone");
				String OrderNo = (String) map.get("OrderNo");
				if (set.contains(OrderNo + phone)) {
					continue;
				}
				ReceiveTimeEngineerOverTime(map);
			}
		}
		
		//获取所有工单状态为服务技师接单未出发和未出发间隔时间
		List<Map<String, Object>> workOrderTMaps = workOrderTDao.getReceiveTimeEngineerWorkOrderTByOrderStatus(params);
		List<Map<String, Object>> newWorkOrderTMaps = new ArrayList<Map<String,Object>>();
		if(workOrderTMaps.size() !=0) {
			for(Map<String, Object> workOrderTMap : workOrderTMaps) {
				String OverTime = workOrderTMap.get("OverTime").toString();
				String TwentyFiveMinutes = PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFiveMinutes").trim();
				if(OverTime.equals(TwentyFiveMinutes)) {
					newWorkOrderTMaps.add(workOrderTMap);
				}	
			}
		}		
		if(newWorkOrderTMaps.size() != 0) {
			for(Map<String, Object> workOrderTMap : newWorkOrderTMaps) {
				//工单号
				String OrderNo = workOrderTMap.get("OrderNo")+"";
				//工单ID
				String OrderId = workOrderTMap.get("ID")+"";
				Map<String, Object> serviceStationIdMap = new HashMap<String, Object>();
				serviceStationIdMap.put("ServiceStationID", Long.parseLong(String.valueOf(workOrderTMap.get("ServiceStationId"))));
				long orderChannel = MapUtils.getLongValue(workOrderTMap,"OrderChannel");
				serviceStationIdMap.put("CompanyID", orderChannel);
				//获取对应服务站服务经理
				Integer isTechSupport = MapUtils.getInteger(workOrderTMap, "IsTechSupport",0);
				List<PositionUserT> positionUserTList = new ArrayList<>();
				if(1==isTechSupport){
					positionUserTList =  positionUserTDao.getManager(serviceStationIdMap);
				}else {
					positionUserTList =   positionUserTDao.getPostUserTListByServiceStationIdCompanyId(serviceStationIdMap);
				}
				if(positionUserTList.size()!=0) {
					for(PositionUserT positionUserT : positionUserTList) {
						String userPhone = positionUserT.getUserPhone();
						String UserName = loginDao.getUserByPhone(userPhone).get(0).getUserName();
						String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
						if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
							//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
							String stationName = MapUtils.getString(workOrderTMap,"StationName","");
							String customerName = MapUtils.getString(workOrderTMap,"CustomerName","");
							String eSN = MapUtils.getString(workOrderTMap,"ESN","");
							String customerComplaint = MapUtils.getString(workOrderTMap,"CustomerComplaint","");
							String createTime = MapUtils.getString(workOrderTMap,"CreateTime","");
							long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,systime);
							String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
							String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
							sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr);
						}else{
							sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
						}
					}
				}
			}
		}		
	}
	
	/**
	 * 未完成工单
	 * 1、开始时间为创建时间
	 * 2、工单已创建，待服务经理确认，待服务商接单，待派服务技师，待服务技师接单，技师已接单，技师已拒单，已出发，已到达
	 *   维修中，待服务经理审核，待400审核-工单创建，待400审核-400回访/诊断中/继续服务/待更新，400审核不通过，诊断中
	 *   诊断完成，待400回访，待400主管审核，这些状态都可以认为未完成工单
	 * @return
	 */
	@Transactional
	public List<Map<String,Object>> getSuccessWorkOrder(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "UnfinishedWorkOrder").trim());
		//因为未完成的工单    一条工单信息会推送给信息员和站长    所以下面的集合保存不重复的工单信息    
		List<Map<String, Object>> distinctOrderIdOederNoMapList = new ArrayList<Map<String,Object>>();
		//查询出对应的工单信息
		List<Map<String,Object>> list = remindTaskService.getSuccessWorkOrder(params);
		if(null!=list&&list.size()>0){
			for(int i=0;i<list.size();i++){
				Map<String,Object> map  = list.get(i);
				SuccessWorkOrder(map);
				//间隔时长
				String OverTime = map.get("OverTime")+"";
				//工单号
				String OrderNo = map.get("OrderNo")+"";
				//工单ID
				String OrderId = map.get("OrderId")+"";
				//服务渠道
				int wotChannel = MapUtils.getIntValue(map,"wotChannel");
				//服务站ID
				String ServiceStationId = map.get("ServiceStationId")+"";
				//ccssOrderNo
				String ccssOrderNo = MapUtils.getString(map,"CCSSOrderNo","");
				//ccec超时24小时未完成
				if(wotChannel == 109){
					if(OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFourHours").trim())){
						Map<String,Object> distinctOrderIdOederNoMap  = new HashMap<String, Object>();
						distinctOrderIdOederNoMap.put("OrderNo",OrderNo);
						distinctOrderIdOederNoMap.put("OrderId",OrderId);
						distinctOrderIdOederNoMap.put("ServiceStationId",ServiceStationId);
						distinctOrderIdOederNoMap.put("wotChannel",wotChannel);
						distinctOrderIdOederNoMap.put("ccssOrderNo",ccssOrderNo);
						if(!distinctOrderIdOederNoMapList.contains(distinctOrderIdOederNoMap)) {
							distinctOrderIdOederNoMapList.add(distinctOrderIdOederNoMap);   //集合添加超时24小时并且不重复的工单信息
						}
					}
				}else{
					if(OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "EightHours").trim())||
							OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFourHours").trim())||
							OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FortyEightHours").trim())){
						Map<String,Object> distinctOrderIdOederNoMap  = new HashMap<String, Object>();
						distinctOrderIdOederNoMap.put("OrderNo",OrderNo);
						distinctOrderIdOederNoMap.put("OrderId",OrderId);
						distinctOrderIdOederNoMap.put("ServiceStationId",ServiceStationId);
						distinctOrderIdOederNoMap.put("wotChannel",wotChannel);
						if(wotChannel == 4){
							distinctOrderIdOederNoMap.put("StationName",MapUtils.getString(map,"StationName",""));
							distinctOrderIdOederNoMap.put("CustomerName",MapUtils.getString(map,"CustomerName",""));
							distinctOrderIdOederNoMap.put("ESN",MapUtils.getString(map,"ESN",""));
							distinctOrderIdOederNoMap.put("CustomerComplaint",MapUtils.getString(map,"CustomerComplaint",""));
							distinctOrderIdOederNoMap.put("CreateTime",MapUtils.getString(map,"CreateTime",""));
							distinctOrderIdOederNoMap.put("OverTimes",OverTime);
							Integer IsTechSupport = MapUtils.getInteger(map, "IsTechSupport", 0);
							distinctOrderIdOederNoMap.put("IsTechSupport",IsTechSupport);
						}
						if(!distinctOrderIdOederNoMapList.contains(distinctOrderIdOederNoMap)) {
							distinctOrderIdOederNoMapList.add(distinctOrderIdOederNoMap);   //集合添加超时8小时，24小时，48小时并且不重复的工单信息
						}
					}
					if(wotChannel == 4 && (OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "SevenHours").trim())||
							OverTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyHours").trim()))){
						Map<String,Object> distinctOrderIdOederNoMap  = new HashMap<String, Object>();
						distinctOrderIdOederNoMap.put("OrderNo",OrderNo);
						distinctOrderIdOederNoMap.put("OrderId",OrderId);
						distinctOrderIdOederNoMap.put("ServiceStationId",ServiceStationId);
						distinctOrderIdOederNoMap.put("wotChannel",wotChannel);
						distinctOrderIdOederNoMap.put("StationName",MapUtils.getString(map,"StationName",""));
						distinctOrderIdOederNoMap.put("CustomerName",MapUtils.getString(map,"CustomerName",""));
						distinctOrderIdOederNoMap.put("ESN",MapUtils.getString(map,"ESN",""));
						distinctOrderIdOederNoMap.put("CustomerComplaint",MapUtils.getString(map,"CustomerComplaint",""));
						distinctOrderIdOederNoMap.put("CreateTime",MapUtils.getString(map,"CreateTime",""));
						distinctOrderIdOederNoMap.put("OverTimes",OverTime);
						Integer IsTechSupport = MapUtils.getInteger(map, "IsTechSupport", 0);
						distinctOrderIdOederNoMap.put("IsTechSupport",IsTechSupport);
						if(!distinctOrderIdOederNoMapList.contains(distinctOrderIdOederNoMap)) {
							distinctOrderIdOederNoMapList.add(distinctOrderIdOederNoMap);   //集合添加xcec超时7小时，20小时并且不重复的工单信息
						}
					}
				}
			}
		}
		
		//服务经理 ccec400消息推送
		if(CollectionUtils.isNotEmpty(distinctOrderIdOederNoMapList)){
			for(Map<String, Object> m :distinctOrderIdOederNoMapList) {
				//工单号
				String OrderNo = m.get("OrderNo")+"";
				//工单ID
				String OrderId = m.get("OrderId")+"";
				//服务站ID
				String ServiceStationId = m.get("ServiceStationId")+"";
				//服务渠道
				int wotChannel = MapUtils.getIntValue(m,"wotChannel");
				//ccssOrderNo
				String ccssOrderNo = MapUtils.getString(m,"ccssOrderNo","");
				Integer IsTechSupport = MapUtils.getInteger(m, "IsTechSupport", 0);
				List<Map<String,Object>> managerList = new ArrayList<>();
				if (1==IsTechSupport) {
					managerList = remindTaskService.getManager(ServiceStationId,wotChannel);
				}else {
					managerList = remindTaskService.getRegionalServiceManager(ServiceStationId,wotChannel);
				}
				if(null!=managerList&&managerList.size()>0){
					for(int i=0;i<managerList.size();i++){
						Map<String,Object> managerMap = managerList.get(i);
						String userPhone = managerMap.get("UserPhone")+"";
						String UserName = managerMap.get("UserName")+"";
						String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
						if(wotChannel == 109){
							sendMsgCCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,9,ccssOrderNo);
						}else{
							if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
								//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
								String OverTimes = MapUtils.getString(m,"OverTimes","");   //分钟
								long overTimeSeconds = Long.parseLong(OverTimes)*60 ;  //秒
								String stationName = MapUtils.getString(m,"StationName","");
								String customerName = MapUtils.getString(m,"CustomerName","");
								String eSN = MapUtils.getString(m,"ESN","");
								String customerComplaint = MapUtils.getString(m,"CustomerComplaint","");
								String createTime = MapUtils.getString(m,"CreateTime","");
								long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,systime);
								if(overTimeSeconds > dealTimeL){
									dealTimeL = overTimeSeconds;
								}
								String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
								String sendMsg = "";
								if (StringUtils.isNotEmpty(OverTimes) && OverTimes.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "SevenHours").trim())){
									// sprint18：新增以下短信发送：
									// 1）区域经理接收7小时预警提醒短信，①短信模板：7小时预警提醒：XX服务商，现有维修工单将超时，请尽快处理 ②发送机制：服务总时长大于等于7小时实时发送，服务总时长=技师完成维修时间-工单创建时间；
									// 2）区域经理接收重大故障提醒短信，①短信模板：重大故障提醒：XXX服务商，,发动机号XXX，现有重大故障工单，请尽快处理 ②发送机制：技师接单点开始维修选择故障级别，如果选择是重大故障提交后短信实时提醒。
									sendMsg = String.format(xcecSevenHourStr, stationName);
									sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 25, 2,sendMsg);
								} else {
									sendMsg = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
									sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,sendMsg);
								}
							}else{
								sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
							}
						}
					}
				}
			}
		}

		return list;
	}
	
	
	/**
	 * 服务商超时未接单处理
	 * @param map
	 */
	@Transactional
	public  void  ServerStationOverTime(Map<String,Object> map){
		String currentTime = LocalTimeUtil.getRealCurrentTime();
		//工单服务渠道
		long orderChannel = Long.parseLong(map.get("OrderChannel").toString());
		//间隔时长
		String overTime = map.get("OverTime")+"";
		//用户名
		String userName = map.get("UserName")+"";
		//用户电话
		String Phone = map.get("Phone")+"";
		//工单号
		String OrderNo = map.get("OrderNo")+"";
		//工单ID
		String OrderId = map.get("OrderId")+"";
		//用户ID
		String UserId = map.get("UserId")+"";
		//5 分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FiveMinutes").trim())){
			if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
			}else if (orderChannel != 1){  //其他渠道走之前推送公共方法
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
			}
			//服务商五分钟超时未接单  判断redis中是否存在key   避免重复覆盖值   需要插入redis中
//			if(orderChannel == 1){
//				setOverTimeKey(OrderId, OverTimeType.TYPE2);
//			}
		}
		//sprint17中改成服务站超时10分钟未接单
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())){
			if(orderChannel == 1){
				setOverTimeKey(OrderId, OverTimeType.TYPE2);
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
			}

		}


		//DBU只在服务商超时五分钟未接单时给服务站站长和信息员推送消息
		//DCEC在服务商超时五分钟十分钟和十五分钟是给服务站站长和信息员推送消息
		//所以DBU没有以下逻辑   DCEc有以下逻辑
		if(orderChannel == 3 || orderChannel == 4){
			//10 分钟推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())){
				if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				}
			}

			//15 分钟推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())){
				if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				}
			}
		}
	}
	
	/**
	 * 服务技师超时未接单处理
	 * @param map
	 */
	@Transactional
	public  void  ServiceStationTechnicianOverTime(Map<String,Object> map){
		String currentTime = LocalTimeUtil.getRealCurrentTime();
        //服务渠道
        long orderChannel = Long.parseLong(map.get("OrderChannel").toString());
		//间隔时长
		String overTime = map.get("OverTime")+"";
		//用户名
		String userName = map.get("UserName")+"";
		//用户电话
		String Phone = map.get("Phone")+"";
		//工单号
		String OrderNo = map.get("OrderNo")+"";
		//工单ID
		String OrderId = map.get("OrderId")+"";
		//用户ID
		String UserId = map.get("UserId")+"";
		//5分钟推送逻辑   ///  版本3.4.0  DBU  服务技师接单超时1、超时规则：超过10分钟未接单；2、计算规则：技师接单-待技师接单时间>10分钟；
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FiveMinutes").trim())){
			if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
			}else{
				if (orderChannel != 1) { //将dbu的排除
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				}

			}

//			//服务商五分钟超时未接单  判断redis中是否存在key   避免重复覆盖值   需要插入redis中
//			if(orderChannel == 1){
//				setOverTimeKey(OrderId,OverTimeType.TYPE3);
//			}
		}
		if (overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())) {
			if (orderChannel == 1) {
				//发送短信
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				//服务商十分钟超时未接单  判断redis中是否存在key   避免重复覆盖值   需要插入redis中
				setOverTimeKey(OrderId, OverTimeType.TYPE3);
			}
		}


		//DBU只有5分钟逻辑    DCEC有10分钟和15分钟
		if(orderChannel == 3 || orderChannel == 4){
            //10 分钟推送逻辑
            if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())){
				if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				}
            }


            //15 分钟推送逻辑
            if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())){
				if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
				}
            }
        }
	}
	
	
	/**
	 * 服务技师接单未出发
	 * @param map
	 */
	@Transactional
	public  void  ReceiveTimeEngineerOverTime(Map<String,Object> map){
		String currentTime = LocalTimeUtil.getRealCurrentTime();
		//服务渠道
		long orderChannel = Long.parseLong(map.get("OrderChannel").toString());
		//间隔时长
		String overTime = map.get("OverTime")+"";
		//用户名
		String userName = map.get("UserName")+"";
		//用户电话
		String Phone = map.get("Phone")+"";
		//工单号
		String OrderNo = map.get("OrderNo")+"";
		//工单ID
		String OrderId = map.get("OrderId")+"";
		//用户ID
		String UserId = map.get("UserId")+"";
		
		//15 分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())){
			if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
			}else{
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
			}
		}


		//20 分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyMinutes").trim())){
			if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
			}else{
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
			}
		}
		
		
		//25 分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFiveMinutes").trim())){
			if(orderChannel == 4){   //2.4.0  xcec渠道补充了字段
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,xcecAddWordsArtStr);
			}else{
				sendMsg(Phone, OrderNo, userName, OrderId, UserId, 7, 2);
			}
		}
		// dbu  超时规则：出发延误原因1、超时规则：90分钟未出发；2、计算规则：出发时间-技师接单时间>90分钟；
		if (overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "NinetyMinutes").trim())) {
			if (orderChannel == 1) {
				//设置超时状态    //服务商90分钟超时未接单  判断redis中是否存在key   避免重复覆盖值   需要插入redis中
				setOverTimeKey(OrderId, OverTimeType.TYPE4);
			}
		}
	}
	
	
	
	/**
	 * 未完成工单超时提醒
	 * @param map
	 */
	@Transactional
	public  void  SuccessWorkOrder(Map<String,Object> map){
		String currentTime = LocalTimeUtil.getRealCurrentTime();
		//间隔时长
		String overTime = map.get("OverTime")+"";
		//用户名
		String userName = map.get("UserName")+"";
		//用户电话
		String Phone = map.get("Phone")+"";
		//工单号
		String OrderNo = map.get("OrderNo")+"";
		//工单ID
		String OrderId = map.get("OrderId")+"";
		//用户ID
		String UserId = map.get("UserId")+"";
		//服务站ID
		String ServiceStationId = map.get("ServiceStationId")+"";
		//服务渠道
		int wotChannel = MapUtils.getIntValue(map,"wotChannel");
		//CCSSOrderNo
		String ccssOrderNo = MapUtils.getString(map,"CCSSOrderNo","");
		if(wotChannel == 109){   //ccec只有24小时
			//24小时推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFourHours").trim())){
				sendMsgCCEC(Phone, OrderNo, userName, OrderId, UserId, 7, 2,8,ccssOrderNo);
			}
		}else{
			/*case 14:smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超24小时，请尽快处理。";
			case 15:smstext =  "您有未处理工单，工单号"+OrderNo+"，工单已超48小时，请尽快处理。";
			case 16:smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超8小时，请尽快处理。";
			case 17:smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超20小时，请尽快处理。";
			case 18:smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超7小时，请尽快处理。";*/
			//2.4.0需求xcec增加7小时推送逻辑
			if(wotChannel == 4 && overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "SevenHours").trim())){
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				/*long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);*/
				String dealTimeStr = "7小时";
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 18, 2,xcecAddWordsArtStr);
			}

			//8小时推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "EightHours").trim())){
				if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					/*long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);*/
					String dealTimeStr = "8小时";
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 16, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 16, 2);
				}
			}

			//2.4.0需求xcec增加20小时推送逻辑
			if(wotChannel == 4 && overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyHours").trim())){
				//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
				String stationName = MapUtils.getString(map,"StationName","");
				String customerName = MapUtils.getString(map,"CustomerName","");
				String eSN = MapUtils.getString(map,"ESN","");
				String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
				String createTime = MapUtils.getString(map,"CreateTime","");
				/*long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
				String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);*/
				String dealTimeStr = "20小时";
				String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
				sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 17, 2,xcecAddWordsArtStr);
			}

			//24小时推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyFourHours").trim())){
				if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					/*long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);*/
					String dealTimeStr = "1天";
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 14, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 14, 2);
				}
			}

			//48小时推送逻辑
			if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FortyEightHours").trim())){
				if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
					//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
					String stationName = MapUtils.getString(map,"StationName","");
					String customerName = MapUtils.getString(map,"CustomerName","");
					String eSN = MapUtils.getString(map,"ESN","");
					String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
					String createTime = MapUtils.getString(map,"CreateTime","");
					/*long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
					String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);*/
					String dealTimeStr = "2天";
					String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
					sendMsgXCEC(Phone, OrderNo, userName, OrderId, UserId, 15, 2,xcecAddWordsArtStr);
				}else{
					sendMsg(Phone, OrderNo, userName, OrderId, UserId, 15, 2);
				}
			}
		}
	}

	/**
	 * 区域服务经理新工单超时未确认提醒
	 * @param map
	 */
	@Transactional
	public  void  NewWorkOrderList(Map<String,Object> map){
		//工单号
		String OrderNo = map.get("OrderNo")+"";
		String OrderId = map.get("OrderId")+"";
		//服务站ID
		String ServiceStationId = map.get("ServiceStationId")+"";
		//间隔时长
		String overTime = map.get("OverTime")+"";
		//工单来源
		String OrderSource = map.get("OrderSource")+"";
		Integer intOrderSource = Integer.parseInt(OrderSource);
		//修改时间
		String UpdateTime = map.get("UpdateTime")+"";
		//当前时间
		String currentTime = LocalTimeUtil.getRealCurrentTime();
		//服务渠道
		int wotChannel = MapUtils.getIntValue(map,"wotChannel");
		//5分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FiveMinutes").trim())){
			//服务经理消息推送
			List<Map<String,Object>> managerList = remindTaskService.getRegionalServiceManager(ServiceStationId,wotChannel);
			if(null!=managerList&&managerList.size()>0){
				for(int i=0;i<managerList.size();i++){
					Map<String,Object> managerMap = managerList.get(i);
					String userPhone = managerMap.get("UserPhone")+"";
					String UserName = managerMap.get("UserName")+"";
					String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
					if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
						// sprint18: 5分钟不要了
//						//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
//						String stationName = MapUtils.getString(map,"StationName","");
//						String customerName = MapUtils.getString(map,"CustomerName","");
//						String eSN = MapUtils.getString(map,"ESN","");
//						String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
//						String createTime = MapUtils.getString(map,"CreateTime","");
//						long overTimeSeconds = Long.parseLong(overTime)*60;   //超时秒数
//						long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
//						if(overTimeSeconds > dealTimeL){
//							dealTimeL = overTimeSeconds;
//						}
//						String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
//						String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
//						sendMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr);
					}else{
						sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
					}
				}
			}
		}		
				
		//10 分钟推送逻辑
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())){

			Integer IsTechSupport = MapUtils.getInteger(map,"IsTechSupport",0);
			List<Map<String,Object>> managerList = new ArrayList<>();
			if(IsTechSupport==1){
				//大工匠工单给   大区经理发送
				 managerList = remindTaskService.getManager(ServiceStationId,wotChannel);
			}else {
				//服务经理消息推送
				managerList = remindTaskService.getRegionalServiceManager(ServiceStationId,wotChannel);
			}
			if(null!=managerList&&managerList.size()>0){
				for(int i=0;i<managerList.size();i++){
					Map<String,Object> managerMap = managerList.get(i);
					String userPhone = managerMap.get("UserPhone")+"";
					String UserName = managerMap.get("UserName")+"";
					String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
					if(wotChannel == 4){   //2.4.0  xcec渠道补充了字段
						//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
						String stationName = MapUtils.getString(map,"StationName","");
						String customerName = MapUtils.getString(map,"CustomerName","");
						String eSN = MapUtils.getString(map,"ESN","");
						String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
						String createTime = MapUtils.getString(map,"CreateTime","");
						long overTimeSeconds = Long.parseLong(overTime)*60;   //超时秒数
						long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
						if(overTimeSeconds > dealTimeL){
							dealTimeL = overTimeSeconds;
						}
						String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);
//						String xcecAddWordsArtStr = String.format(xcecAddWordsArt, stationName,customerName,eSN,customerComplaint,dealTimeStr);
						String distance = MapUtils.getString(map,"GuessDistance","0");
						String xcecAddWordsArtStr = String.format(xcecOverTimeBody, stationName,OrderNo,distance);
						if (overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())) {
							// function=27: XCEC区域经理接收外出审批单提醒
							sendQYFWJLMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr,1);						}
					}else{
						sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
					}
				}
			}
		}		
				
		//15 分钟或者20分钟推送逻辑
        //新增xcec 30分钟默认通过: sprint18需求：30分钟自动审批后不再发短信
		if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())
                || overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyMinutes").trim())
				|| (wotChannel == 4 && overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "Halfhour").trim()))) {
			Long smId = 0L;   //区域服务经理id   下面工单操作表需要

			Integer IsTechSupport = MapUtils.getInteger(map,"IsTechSupport",0);
			List<Map<String,Object>> managerList = new ArrayList<>();
			if(IsTechSupport==1){
				//大工匠工单给   大区经理发送
				managerList = remindTaskService.getManager(ServiceStationId,wotChannel);
			}else {
				//服务经理消息推送
				managerList = remindTaskService.getRegionalServiceManager(ServiceStationId,wotChannel);
			}
			if(null!=managerList&&managerList.size()>0){
				for(int i=0;i<managerList.size();i++){
					Map<String,Object> managerMap = managerList.get(i);
					String userPhone = managerMap.get("UserPhone")+"";
					String UserName = managerMap.get("UserName")+"";
					String UserID = String.valueOf(loginDao.getUserByPhone(userPhone).get(0).getId());
					smId = (Long) managerList.get(0).get("ID");
                    if (wotChannel == 3) {
						sendQYFWJLMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
					}else if(wotChannel == 4){
						//xcec短信提醒新增字段服务站名称:%，工单号:%，客户姓名:%，发动机号:%，发动机故障描述:%，工单处理时长:%分钟
						String stationName = MapUtils.getString(map,"StationName","");
						String customerName = MapUtils.getString(map,"CustomerName","");
						String eSN = MapUtils.getString(map,"ESN","");
						String customerComplaint = MapUtils.getString(map,"CustomerComplaint","");
						String createTime = MapUtils.getString(map,"CreateTime","");
						long overTimeSeconds = Long.parseLong(overTime)*60;   //超时秒数
						long dealTimeL = LocalTimeUtil.getDurationSeconds(createTime,currentTime);
						if(overTimeSeconds > dealTimeL){
							dealTimeL = overTimeSeconds;
						}
						String dealTimeStr = LocalTimeUtil.formatDateTime(dealTimeL);

						String distance = MapUtils.getString(map,"GuessDistance","0");
						String xcecAddWordsArtStr = String.format(xcecOverTimeBody, stationName,OrderNo,distance);
                        if (overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TwentyMinutes").trim())) {
							// function=27: XCEC区域经理接收外出审批单提醒
							sendQYFWJLMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr,1);
                        }
                        // sprint18需求：30分钟自动审批后不再发短信
//                        else if (overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "Halfhour").trim())) {
//							sendQYFWJLMsgXCEC(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2,xcecAddWordsArtStr,2);
//						}
					}else{
						sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
					}

				}
			}
			//dcec15分钟默认通过    2.1.0需求    dcec区域服务经理取消超时15分钟默认通过
			if (wotChannel == 3 && overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())) {
				defaultPass(intOrderSource,OrderNo,currentTime,UpdateTime,ServiceStationId,map,OrderId,smId,wotChannel);
			}
            //xcec30分钟默认通过   2.9.0改为30分钟
			//sprint52 CDAP-4945取消xcec区域服务经理默认审核通过
           /* if (wotChannel == 4 && overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "Halfhour").trim())) {
				defaultPass(intOrderSource,OrderNo,currentTime,UpdateTime,ServiceStationId,map,OrderId,smId,wotChannel);
			}*/
		}
	}

	//区域服务经理默认通过工单公用方法
	@Transactional
	public void defaultPass(int intOrderSource,String OrderNo,String currentTime,String UpdateTime,String ServiceStationId,Map<String,Object> map,String OrderId,Long smId,int wotChannel){
		int orderStatus = 2;
		String smstext = "";
		if(intOrderSource == 0 || intOrderSource == 2 || intOrderSource == 4) {
			orderStatus = 4;
			smstext = "您有新工单信息，工单号"+OrderNo+"，请尽快处理。";
			Map<String, Object> updateUserMap = new HashMap<String, Object>();
			updateUserMap.put("OrderStatus", orderStatus);
			updateUserMap.put("updateTime", currentTime);
			updateUserMap.put("OrderNo", OrderNo);
			updateUserMap.put("UpdateTime", UpdateTime);
			updateUserMap.put("isShowStation", 0);
			workOrderTDao.updatePassWorkOrderByUser(updateUserMap);
		}
		//服务站APP报修/服务站CRM报修
		if(intOrderSource == 1 || intOrderSource == 3) {
			orderStatus = 6;
			smstext = "您有工单待指派技师，工单号"+OrderNo+"，请尽快处理。";
			Map<String, Object> updateServiceStationMap = new HashMap<String, Object>();
			updateServiceStationMap.put("OrderStatus", orderStatus);
			updateServiceStationMap.put("updateTime", currentTime);
			updateServiceStationMap.put("OrderNo", OrderNo);
			updateServiceStationMap.put("UpdateTime", UpdateTime);
			updateServiceStationMap.put("isShowStation", 0);
			workOrderTDao.updatePassWorkOrderByServerStation(updateServiceStationMap);
		}
		//插入工单负责人表
		map.put("ServiceStationID", ServiceStationId);
		//插入消息提醒表
		List<Map<String, Object>> saveMsgOperationMapList = new ArrayList<Map<String,Object>>();
		//获取站长
		List<UserT> zZUserTs = userTDao.getUserTByServiceStationId(map);
		Set<String> set = new HashSet<>();
		if(zZUserTs.size()!=0) {
			for(UserT userT : zZUserTs) {
				//区域服务经理是创建人，但有可能多个，这里创建人暂时用
				workOrderTServiceImpl.savePrincipal(Long.parseLong(OrderId),orderStatus,1,userT.getId(),smId,currentTime);
				SmsUtils.sendMessage(userT.getPhone(), smstext);
				saveMsgOperationMapList.add(workOrderTServiceImpl.saveMsgOperation(Long.parseLong(OrderId),2,1,userT.getId(),smstext,1,currentTime,"服务经理超时默认通过",smId));
				// APP推送
				set.add(userT.getPhone());
				noticeService.push(2,1, Long.valueOf(OrderId),userT.getId(),userT.getUserName(),null,smstext,smstext,smId);
			}
		}
		//获取信息员
		List<UserT> xXYUserTs = userTDao.getMsgUserTByServiceStationId(map);
		if(xXYUserTs.size()!=0) {
			for(UserT userT : xXYUserTs) {
				//区域服务经理是创建人，但有可能多个，这里创建人暂时用
				if (set.contains(userT.getPhone())) {
					continue;
				}
				workOrderTServiceImpl.savePrincipal(Long.parseLong(OrderId),orderStatus,1,userT.getId(),smId,currentTime);
				SmsUtils.sendMessage(userT.getPhone(), smstext);
				saveMsgOperationMapList.add(workOrderTServiceImpl.saveMsgOperation(Long.parseLong(OrderId),2,1,userT.getId(),smstext,1,currentTime,"服务经理超时默认通过",smId));
				// APP推送
				noticeService.push(2,1, Long.valueOf(OrderId),userT.getId(),userT.getUserName(),null,smstext,smstext,smId);
			}
		}
		if(CollectionUtils.isNotEmpty(saveMsgOperationMapList)){
			workOrderRepairDao.saveMsgOperation(saveMsgOperationMapList);   //插入并保存消息提醒数据
		}
		//插入工单操作表
		workOrderTServiceImpl.saveOperation(Long.parseLong(OrderId),smId,orderStatus,"服务经理超时默认通过","","","","",0,smId,currentTime);
		//同步crm
		//if(wotChannel == 4){
			syncCRMNewWorkOrderList(map,orderStatus,wotChannel);
		//}
	}

	//dcec带区域服务经理确认工单超市15分钟自动审批通过，xcec待区域服务经理确认工单超时20(xcec)分钟自动审批通过（同步crm）公共方法
	public void syncCRMNewWorkOrderList(Map<String,Object> map,int orderStatus,int wotChannel){
		Map<String, Object> tbMap = new HashMap<String, Object>();
		String orderNo = map.get("OrderNo").toString();
		tbMap.put("orderNo", map.get("OrderNo"));
		Map<String,Object> workOrder = workOrderTDao.getOrderByNo(orderNo);
		if(MapUtils.isNotEmpty(workOrder)){
			tbMap.put("CRMNo", MapUtils.getString(workOrder,"OrderNoCrm"));
			long oldOrderId = MapUtils.getLongValue(workOrder,"RelOrderIdOld",0);
			if(oldOrderId != 0){
				Map<String,Object> oldWorkOrder = workOrderTDao.getOrderById(oldOrderId);
				tbMap.put("oldOrderNo", MapUtils.getString(oldWorkOrder,"OrderNo"));
			}
		}
		tbMap.put("billStatus", orderStatus);
		tbMap.put("actionTime", LocalTimeUtil.getRealCurrentTime());
		tbMap.put("directorName", "系统任务");
		tbMap.put("directorPhone", "");
		Map<String,Object> stationMap = serviceStationDao.getStationNoAndNameByStationIdAndCompanyId(MapUtils.getLongValue(map,"ServiceStationId"),wotChannel);
		if(MapUtils.isNotEmpty(stationMap)){
			tbMap.put("stationNo", stationMap.get("BusinessNo"));
		}
		tbMap.put("phoneIMEI", "");
		tbMap.put("positionLat", 0);
		tbMap.put("positionLon", 0);
		tbMap.put("location", "");
		tbMap.put("isAutoPass", 1);  //是否自动审批通过(0：否；1：是)
		CompanyT companyT = companyTDao.getCompanyInfoByCompanyID(wotChannel);
		try {
			CRMResponeEntity CRMres = CRMApiUtils.getCRMServiceApi()
					.syncOrderStatusToCrm(companyT.getAbbreviation(),platformServiceDao,redisClientUtils,tbMap,null);
			if(CRMres.getStatus() != 0) {
				log.error("同步工单状态至CRM失败!状态:" + CRMres.getStatus() + ",错误信息:" + CRMres.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("同步工单状态至CRM失败!错误信息:" + e.getMessage(),e);
		}
	}

	public Map<String, Object> OrderStatusToCrmMap(Map<String, Object> orgOrderMap, Map<String, Object> map) {
		Map<String, Object> tbMap = new HashMap<String, Object>();
		tbMap.put("orderNo", orgOrderMap.get("OrderNo"));
		if (!"".equals(org.apache.commons.collections4.MapUtils.getString(orgOrderMap, "OrderNoCrm", ""))) {
			tbMap.put("CRMNo", orgOrderMap.get("OrderNoCrm"));
		}
		tbMap.put("oldOrderNo", map.get("oldOrderNo"));
		tbMap.put("billStatus", orgOrderMap.get("OrderStatus"));
		if (map.containsKey("RefuseType")){
			tbMap.put("refuseType", map.get("RefuseType"));// 2 用户不需要维修
		}
		tbMap.put("refuseReason", map.get("RefuseContent"));
		tbMap.put("actionTime", LocalTimeUtil.getRealCurrentTime());
		tbMap.put("directorName", map.get("contact"));
		tbMap.put("directorPhone", map.get("phone"));
		tbMap.put("stationNo", map.get("BusinessNo"));

		return tbMap;
	}

	//DBU区域工程师超时未处理工单   超时提醒
	@Transactional
	public void areaEngineerOverTimeUnDealRemind(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus18").trim());
		//查询出对应的工单信息
		List<Map<String,Object>> list = remindTaskService.getAreaEngineerWorkOrderList(params);
		if(CollectionUtils.isNotEmpty(list)){
			for(int i=0;i<list.size();i++){
				Map<String,Object> map  = list.get(i);
				//区域服务经理超时未确认工单
				//工单号
				String OrderNo = map.get("OrderNo")+"";
				String OrderId = map.get("OrderId")+"";
				//间隔时长
				String overTime = map.get("OverTime")+"";
				//15分钟推送逻辑，sprint17修改为10分钟
//				if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "FifteenMinutes").trim())){
				if(overTime.equals(PropertiesUtil.getProperties("workOrderStatus.properties", "TenMinutes").trim())){
                    //区域工程师超时15分钟未处理工单   插入redis中数据
					setOverTimeKey(OrderId,OverTimeType.TYPE1);
					//区域工程师消息推送
					Map<String,Object> recommendThreeStationMap = allServiceStationDao.getRecommendThreeStationForDBUByOrderId(Long.parseLong(OrderId));
					if(MapUtils.isNotEmpty(recommendThreeStationMap)){
						String managerPhone = MapUtils.getString(recommendThreeStationMap,"DBEngineerPhone");
						List<UserT> managerList	= loginDao.getUserByPhone(managerPhone);
						if(CollectionUtils.isNotEmpty(managerList)){
							for(UserT manager : managerList){
								String userPhone = manager.getPhone();
								String UserName = manager.getUserName();
								String UserID = String.valueOf(manager.getId());
								sendMsg(userPhone, OrderNo, UserName, OrderId, UserID, 7, 2);
							}
						}
					}
				}
			}
		}

	}


	//待用户评价工单超时2小时(xcec)和24小时(其他渠道)，超时半小时(ccec  待用户评价-400远程解决)未评价自动变为服务完成工单
	//ccec待用户评价超时半小时未评价  工单状态转为待400回访
	@Transactional
	public void getWaitUserEvaluateWorkOrderList(String systime){
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		params.put("orderstatus", PropertiesUtil.getProperties("workOrderStatus.properties", "OrderStatus13").trim());
		CompanyT ccecCompany = companyTDao.getCompanyInfoByCompanyNo("CCEC");
		params.put("ccecCompanyId",ccecCompany.getId());
		//查询出对应的工单信息
		List<Map<String,Object>> waitUserEvaluateWorkOrderList = remindTaskService.getWaitUserEvaluateWorkOrderList(params);
		if(CollectionUtils.isNotEmpty(waitUserEvaluateWorkOrderList)){
			for(Map<String,Object> waitUserEvaluateWorkOrder : waitUserEvaluateWorkOrderList){
				long orderId = MapUtils.getLongValue(waitUserEvaluateWorkOrder,"ID");
				int overTime = MapUtils.getIntValue(waitUserEvaluateWorkOrder,"overTime");
				long orderChannel = MapUtils.getLongValue(waitUserEvaluateWorkOrder,"OrderChannel");
				String orderNo = MapUtils.getString(waitUserEvaluateWorkOrder,"OrderNo");
				String crmNo = MapUtils.getString(waitUserEvaluateWorkOrder,"OrderNoCrm");
				int currentOrderStatus = MapUtils.getIntValue(waitUserEvaluateWorkOrder,"OrderStatus");
				if(orderChannel == ccecCompany.getId()){  //ccec走这个逻辑
					if(overTime >= 1){   //大于半小时的待用户评价和待用户评价-400远程解决的工单
						if(currentOrderStatus == 13){   //待用户评价超时半小时   工单状态改为待400回访
							int orderStatus = 32;    //32	 待400回访
							String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
							Map<String,Object> updateOrderMap = new HashMap<>();
							updateOrderMap.put("ID", orderId);
							updateOrderMap.put("OrderStatus", orderStatus);
							updateOrderMap.put("Updator", -1);
							updateOrderMap.put("UpdateTime", currentTime);
							int saveWorkOrderByUserAPPAppraiseResult = workOrderTDao.saveWorkOrderByUserAPPAppraise(updateOrderMap);  //修改工单状态
							//插入工单操作记录表
							workOrderTServiceImpl.saveOperation(orderId,-1,orderStatus,"用户评价--待400回访","","","","",0,-1,currentTime);
							Map<String,Object> areaManagerMsgMap = new HashMap<>();
							Map<String,Object> workOrderMap = workOrderTDao.getOrderByNo(orderNo);
							areaManagerMsgMap.put("ServiceStationId",MapUtils.getLong(workOrderMap,"ServiceStationId"));
							areaManagerMsgMap.put("OrderChannel",MapUtils.getLong(workOrderMap,"OrderChannel"));
							List<Map<String,Object>> notifyRecordTMapList = new ArrayList<>();
							List<Map<String,Object>> AreaManagerMapList = workOrderRepairDao.getAreaManager(areaManagerMsgMap);
							String msgbody = "";
							if(StringUtils.isNotEmpty(MapUtils.getString(workOrderMap,"CCSSOrderNo",""))){
								msgbody = "您有工单待回访，工单号"+MapUtils.getString(workOrderMap,"OrderNo")+"（FW号"+MapUtils.getString(workOrderMap,"CCSSOrderNo","")+"），请处理。";
							}else{
								msgbody = "您有工单待回访，工单号"+MapUtils.getString(workOrderMap,"OrderNo")+"，请处理。";
							}
							if(CollectionUtils.isNotEmpty(AreaManagerMapList)){
								for(Map<String,Object> AreaManagerMap : AreaManagerMapList){
									long  receiverId = MapUtils.getLongValue(AreaManagerMap,"ID");
									String receiverUserName = MapUtils.getString(AreaManagerMap,"UserName");
									String phone = MapUtils.getString(AreaManagerMap,"phone","");
									workOrderTServiceImpl.savePrincipal(orderId,orderStatus,1,receiverId,-1,currentTime);
									noticeService.push(2,1,orderId,receiverId,receiverUserName,"新工单提醒",msgbody,msgbody,-1L);
									SmsUtils.sendMessage(phone, msgbody);
									notifyRecordTMapList.add(workOrderTServiceImpl.saveMsgOperation(orderId,2,1,receiverId,msgbody,1,currentTime,"",-1));
								}
								if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
									workOrderRepairDao.saveMsgOperation(notifyRecordTMapList);
								}
							}
							syncCRM(orderNo,crmNo,currentTime,orderChannel,orderStatus);
						}else{    //待用户评价-400远程解决超时半小时   工单状态改为服务完成
							String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
							saveWorkOrderByUserAPPAppraise(orderId,currentTime);
							syncCRM(orderNo,crmNo,currentTime,orderChannel,14);
						}
					}
				}else{
					if(orderChannel == 4){
						if(overTime >= 2){   //大于2小时的待用户评价的工单
							//修改工单状态为服务完成
							String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
							saveWorkOrderByUserAPPAppraise(orderId,currentTime);
							syncCRM(orderNo,crmNo,currentTime,orderChannel,14);
						}
					}else{
                        if (orderChannel == 1 && overTime >= 2) {
                            //dbu3.3.0运维需求在3.2.0运维版本中做  dbu从24小时超时改为2小时超时
                            //DBU需要调用CRM接口  2.2.3APP系统同步工单状态信息到CRM系统
                            //修改工单状态为服务完成
                            String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
                            saveWorkOrderByUserAPPAppraise(orderId, currentTime);
                            syncCRM(orderNo, crmNo, currentTime, orderChannel, 14);

                        } else {   //别的逻辑不动
                            if (overTime >= 24) {   //大于24小时的待用户评价的工单
                                //修改工单状态为服务完成
                                String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
                                saveWorkOrderByUserAPPAppraise(orderId, currentTime);
                                //DCEC不用调用CRM接口
							}
						}
					}
				}
			}
		}

	}


	//ccec待更新   超时提醒
	@Transactional
	public void getToBeUpdatedWorkOrderList(String systime){
		//因-1和晓闪冲突      定时任务创建人改为-2
		long taskCreator = -2;
		//获取相应参数
		Map<String,Object> params = new HashMap<>();
		params.put("systime", systime);
		//查询出400审核不通过的工单信息
		List<Map<String,Object>> toBeUpdatedWorkOrderList = remindTaskService.getToBeUpdatedWorkOrderList(params);
		if(CollectionUtils.isNotEmpty(toBeUpdatedWorkOrderList)){
			for(Map<String,Object> toBeUpdatedWorkOrderMap : toBeUpdatedWorkOrderList){
				int overTime = MapUtils.getIntValue(toBeUpdatedWorkOrderMap,"OverTime");
				long orderId = MapUtils.getLongValue(toBeUpdatedWorkOrderMap,"ID");
				long orderChannel = MapUtils.getLongValue(toBeUpdatedWorkOrderMap,"OrderChannel");
				String orderNo = MapUtils.getString(toBeUpdatedWorkOrderMap,"OrderNo");
				String fwNo = MapUtils.getString(toBeUpdatedWorkOrderMap,"CCSSOrderNo","");
				long customerId = MapUtils.getLongValue(toBeUpdatedWorkOrderMap,"CustomerId",-1);  //用户表主键id   客户在系统中时有值
				String customerPhone = MapUtils.getString(toBeUpdatedWorkOrderMap,"CustomerPhone"); //客户手机号
				long serviceStationId = MapUtils.getLongValue(toBeUpdatedWorkOrderMap,"ServiceStationId");  //服务站id
				int orderSource = MapUtils.getIntValue(toBeUpdatedWorkOrderMap,"OrderSource");
				if(10 == overTime || 20 == overTime || 30 == overTime){  //10/20/30分钟推送相关负责人
					//工单来源是0  终端用户APP报修   推送负责人用户
					//工单来源是1  服务站APP报修     推送负责人是站长和信息员
					UserT customerT = new UserT();
					if(orderSource == 0){
						String msg = "您有工单待更新，工单号"+ orderNo +"，请尽快处理。";  //推送话术
						if(-1 != customerId){
							customerT = loginDao.getUserByid(String.valueOf(customerId));
						}
						if(null == customerT){
							List<UserT> users = loginDao.getUserByPhone(customerPhone);
							if(CollectionUtils.isNotEmpty(users)){
								customerT = users.get(0);
							}
						}
						if(null == customerT){
							noticeService.sendSMS(7,2,orderId,0L,customerPhone,msg,taskCreator);
							noticeService.push(7,2,orderId,0L,"","超时工单提醒",msg,msg,taskCreator);
						}else{
							noticeService.sendSMS(7,2,orderId,customerT.getId(),customerT.getPhone(),msg,taskCreator);
							noticeService.push(7,2,orderId,customerT.getId(),customerT.getUserName(),"超时工单提醒",msg,msg,taskCreator);
						}
					}else{
						String msg = "";
						if(StringUtils.isEmpty(fwNo)){
							msg = "您有工单待更新，工单号"+ orderNo +"，请尽快处理。";  //推送话术
						}else{
							msg = "您有工单待更新，工单号"+ orderNo +"（FW号"+ fwNo +"），请尽快处理。";  //推送话术
						}

						List<UserT> serviceStationUserList = userTDao.getStationMasterListByServiceStationId(serviceStationId);
						if(CollectionUtils.isNotEmpty(serviceStationUserList)){
							for(UserT serviceStationUser : serviceStationUserList){
								noticeService.sendSMS(7,2,orderId,serviceStationUser.getId(),serviceStationUser.getPhone(),msg,taskCreator);
								noticeService.push(7,2,orderId,serviceStationUser.getId(),serviceStationUser.getUserName(),"超时工单提醒",msg,msg,taskCreator);
							}
						}
					}
				}else if(overTime >= 40){   //40分钟修改工单状态为待400审核
					String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
					int orderStatus = 24;  //待400审核
					WorkOrderT workOrderT = workOrderTDao.getWorkOrderTByOrderId(orderId);
					Map<String,Object> orderMap = new HashMap<>();
					orderMap.put("ID",workOrderT.getId());
					orderMap.put("Updator",taskCreator);
					orderMap.put("UpdateTime",currentTime);
					orderMap.put("OrderStatus",orderStatus);
					workOrderTDao.updateByPrimaryKeySelective(orderMap);
					UserT userT = new UserT();
					userT.setPhone("");
					userT.setContact("系统定时任务");
					userT.setId(taskCreator);
					workOrderTServiceImpl.sonMethod(workOrderT,orderStatus,currentTime,userT,new HashMap<>(),orderSource);
				}
			}
		}

	}



	//待用户评价工单超时自动转化为服务完成（修改工单状态和插入工单操作记录表）公共方法
	public void saveWorkOrderByUserAPPAppraise(long orderId,String currentTime){
		Map<String,Object> workOrderMap = new HashMap<>();
		workOrderMap.put("ID", orderId);
		workOrderMap.put("OrderStatus", 14);  //工单状态为服务完成
		workOrderMap.put("Updator", -1);
		workOrderMap.put("UpdateTime", currentTime);
		workOrderTDao.saveWorkOrderByUserAPPAppraise(workOrderMap);
		//插入工单操作记录表信息
		Map<String, Object> workOrderFlowTMap = new HashMap<String, Object>();  //新建工单操作记录对象
		workOrderFlowTMap.put("OrderId", orderId);
		workOrderFlowTMap.put("ProcessorId", -1);
		workOrderFlowTMap.put("OrderStatus", 14);  //工单状态为服务完成
		workOrderFlowTMap.put("ProcessComment", "待用户评价超时工单，工单状态变为服务完成");
		workOrderFlowTMap.put("ProLocLon", 0);
		workOrderFlowTMap.put("ProLocLat", 0);
		workOrderFlowTMap.put("ProLocation","");
		workOrderFlowTMap.put("IMEI", "");  //手机串号
		workOrderFlowTMap.put("Flag", 0);
		workOrderFlowTMap.put("Creator",-1);
		workOrderFlowTMap.put("CreateTime", currentTime);
		workOrderRepairDao.saveOperation(workOrderFlowTMap);  //插入并保存工单操作记录数据
	}



	//待用户评价工单超时自动转化为服务完成或待400回访(ccec)（同步crm）公共方法
	public void syncCRM(String orderNo,String crmNo,String currentTime,long orderChannel,int orderStatus){
		Map<String, Object> parameters = new HashMap<>();
		parameters.put("orderNo",orderNo);
		parameters.put("CRMNo",crmNo);
		parameters.put("billStatus",orderStatus);
		parameters.put("actionTime",currentTime);
		parameters.put("directorName","系统任务");
		parameters.put("directorPhone","");
		parameters.put("appAppraise",2);
		parameters.put("positionLat",0);
		parameters.put("positionLon",0);
		parameters.put("phoneIMEI","");
		parameters.put("location","");
		CompanyT ccecCompany = companyTDao.getCompanyInfoByCompanyNo("CCEC");
		if(ccecCompany.getId() == orderChannel){
			Map<String,Object> workOrderMap = workOrderTDao.getOrderByNo(orderNo);
			parameters.put("CCSSComplainerOrderNo",crmNo);
			parameters.put("CCSSOrderNo",MapUtils.getString(workOrderMap,"CCSSOrderNo"));
			parameters.put("customerName",MapUtils.getString(workOrderMap,"CustomerName"));
			parameters.put("customerPhone",MapUtils.getString(workOrderMap,"CustomerPhone"));
			parameters.put("customerCompany",MapUtils.getString(workOrderMap,"CustomerCompanyName"));
			parameters.put("faultDesc",MapUtils.getString(workOrderMap,"CustomerComplaint"));
			Map<String,Object> sSRepair = serviceStationDao.getStationNoAndNameByStationIdAndCompanyId(MapUtils.getLong(workOrderMap,"ServiceStationId"),MapUtils.getLong(workOrderMap,"OrderChannel"));
			if(MapUtils.isNotEmpty(sSRepair)){
				parameters.put("stationNo",sSRepair.get("BusinessNo"));
				parameters.put("stationName",sSRepair.get("StationName"));
			}else{
				parameters.put("stationNo","");
				parameters.put("stationName","");
			}
			parameters.put("drOrderNNo","");
			parameters.put("drDiagnoseReport","");
			parameters.put("doneSolutionList",new ArrayList<>());
			parameters.put("faultInfo","");
			parameters.put("doneSolutionNoStr","");
			EngineMsg engineMsg = engineMsgDao.getEngineMsgByESNString(MapUtils.getString(workOrderMap,"ESN",""));
			if(null != engineMsg){
				parameters.put("SMN",engineMsg.getSMN());
			}else{
				parameters.put("SMN","");
			}
		}
		parameters.put("remark","定时任务");
		String companyNo = companyTDao.getCompanyInfoByCompanyID(orderChannel).getCompanyNo();
		try {
			CRMResponeEntity cRMResponeEntity = CRMApiUtils.getCRMServiceApi().syncOrderStatusToCrm(companyNo,platformServiceDao,redisClientUtils,parameters,null);
			if(cRMResponeEntity.getStatus() != 0) {
				log.error("同步工单状态至CRM失败!状态:" + cRMResponeEntity.getStatus() + ",错误信息:" + cRMResponeEntity.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("同步工单状态至CRM失败!错误信息:" + e.getMessage(),e);
		}
	}


	/*private String msgbodyCCEC1 = "您有新工单信息，工单号%s，请尽快处理。";
	private String msgbodyCCEC2 = "您有新的工单待指派，工单号%s，请尽快处理。";
	private String msgbodyCCEC3 = "您有新的工单信息待处理，工单号%s，请查看。";
	private String msgbodyCCEC4 = "您有工单未出发，工单号%s，工单已超时，请尽快处理。";
	private String msgbodyCCEC5 = "您有工单待400审核，工单号%s，请尽快处理。";
	private String msgbodyCCEC6 = "您有工单待回访，工单号%s，请处理。";
	private String msgbodyCCEC7 = "您有工单待审核，工单号%s，请处理。";
	private String msgbodyCCEC8 = "您有工单未完成，工单号%s，工单已超过24小时，请尽快处理";
	private String msgbodyCCEC9 = "您有未处理工单，工单号%s，工单已超24小时，请尽快处理。";*/
	//ljk  ccec发送消息
	public  void  sendMsgCCEC(String Phone,String OrderNo,String userName,String OrderId,String userid,int function,int category,int type,String ccssOrderNo){
		List<Map<String, Object>> notifyRecordTMapList = new ArrayList<Map<String,Object>>();
		String smstext = "";
		switch (type){
			case 1:
				smstext = msgbodyCCEC1;
				break;
			case 2:
				smstext = msgbodyCCEC2;
				break;
			case 3:
				smstext = msgbodyCCEC3;
				break;
			case 4:
				smstext = msgbodyCCEC4;
				break;
			case 5:
				smstext = msgbodyCCEC5;
				break;
			case 6:
				smstext = msgbodyCCEC6;
				break;
			case 7:
				smstext = msgbodyCCEC7;
				break;
			case 8:
				smstext = msgbodyCCEC8;
				break;
			case 9:
				smstext = msgbodyCCEC9;
				break;
			default:
				smstext = "您有未处理工单，工单号%s，工单已超时，请尽快处理。";
				break;
		}
		if(StringUtils.isNotEmpty(ccssOrderNo)){
			String orderCCSSOrderNo = OrderNo+"（FW号"+ccssOrderNo+")";
			smstext = String.format(smstext, orderCCSSOrderNo);
		}else{
			smstext = String.format(smstext, OrderNo);
		}
		//短信发送
		if(!"".equals(Phone)){
			String reuslt = SmsUtils.sendMessage(Phone, smstext);
			Map<String,Object> map  = getMsgMap(OrderId, smstext, userid, 1, function, category);
			notifyRecordTMapList.add(map);
		}
		if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
			remindTaskService.saveMsgOperation(notifyRecordTMapList);
		}
		// APP推送
		noticeService.push(function,category,Long.valueOf(OrderId),Long.valueOf(userid),userName,null,smstext,"您有未处理工单",0L);
	}




	/**
	 * 发送短信 、APP推送
	 * @param Phone
	 * @param OrderNo
	 */
	public  void  sendMsg(String Phone,String OrderNo,String userName,String OrderId,String userid,int function,int category){
		List<Map<String, Object>> notifyRecordTMapList = new ArrayList<Map<String,Object>>();
		String smstext = "";
		switch (function){
			case 14:
				smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超24小时，请尽快处理。";
				break;
			case 15:
				smstext =  "您有未处理工单，工单号"+OrderNo+"，工单已超48小时，请尽快处理。";
				break;
			case 16:
				smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超8小时，请尽快处理。";
				break;
			case 17:
				smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超20小时，请尽快处理。";
				break;
			case 18:
				smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超7小时，请尽快处理。";
				break;
			default:
				smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超时，请尽快处理。";
				break;
		}
		//短信发送
		if(!"".equals(Phone)){
			String reuslt = SmsUtils.sendMessage(Phone, smstext);
			Map<String,Object> map  = getMsgMap(OrderId, smstext, userid, 1, function, category);
			notifyRecordTMapList.add(map);
		}
		if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
			remindTaskService.saveMsgOperation(notifyRecordTMapList);
		}
		// APP推送
		noticeService.push(function,category,Long.valueOf(OrderId),Long.valueOf(userid),userName,null,smstext,"您有未处理工单",0L);
	}


	public  void  sendMsgXCEC(String Phone,String OrderNo,String userName,String OrderId,String userid,int function,int category,String xcecAddWordsArtStr){
		List<Map<String, Object>> notifyRecordTMapList = new ArrayList<Map<String,Object>>();
		String smstext = "";
		switch (function) {
			case 14:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超24小时，请尽快处理。";
				break;
			case 15:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超48小时，请尽快处理。";
				break;
			case 16:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超8小时，请尽快处理。";
				break;
			case 17:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超20小时，请尽快处理。";
				break;
			case 18:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超7小时，请尽快处理。";
				break;
			default:
				smstext = "您有未处理工单，工单号" + OrderNo + "，工单已超时，请尽快处理。";
				break;
		}
		smstext += xcecAddWordsArtStr;
		//短信发送
		if(!"".equals(Phone)){
			if (function == 25 || function == 27){
				String reuslt = SmsUtils.sendMessage(Phone, xcecAddWordsArtStr);
				Map<String,Object> map  = getMsgMap(OrderId, xcecAddWordsArtStr, userid, 1, function, category);
				notifyRecordTMapList.add(map);
			} else {
				String reuslt = SmsUtils.sendMessage(Phone, smstext);
				Map<String,Object> map  = getMsgMap(OrderId, smstext, userid, 1, function, category);
				notifyRecordTMapList.add(map);
			}
		}
		if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
			remindTaskService.saveMsgOperation(notifyRecordTMapList);
		}
		// APP推送
		noticeService.push(function,category,Long.valueOf(OrderId),Long.valueOf(userid),userName,null,smstext,"您有未处理工单",0L);
	}

	/**
	 * 区域服务经理超时15分钟默认通过发送短信 、APP推送
	 * @param Phone
	 * @param OrderNo
	 */
	public  void  sendQYFWJLMsg(String Phone,String OrderNo,String userName,String OrderId,String userid,int function,int category){
		
		List<Map<String, Object>> notifyRecordTMapList = new ArrayList<Map<String,Object>>();
		String smstext = "您有未确认工单已超时，工单号"+OrderNo+"，默认确认通过，请查看。";
		//短信发送
		if(!"".equals(Phone)){
			String reuslt = SmsUtils.sendMessage(Phone, smstext);
			Map<String,Object> map  = getMsgMap(OrderId, smstext, userid, 1, function, category);
			notifyRecordTMapList.add(map);
		}
		if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
			remindTaskService.saveMsgOperation(notifyRecordTMapList);
		}

		// APP推送
		noticeService.push(function,category,Long.valueOf(OrderId),Long.valueOf(userid),userName,null,smstext,"您有未处理工单",0L);
	}

	public  void  sendQYFWJLMsgXCEC(String Phone,String OrderNo,String userName,String OrderId,String userid,int function,int category,String xcecAddWordsArtStr,int type){

		List<Map<String, Object>> notifyRecordTMapList = new ArrayList<Map<String,Object>>();
		String smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超时，请尽快处理。";
//		if(type == 2){
//			smstext = "您有未处理工单，工单号"+OrderNo+"，工单已超时，请尽快处理。";
//		}
		// sprint18需求：30分钟自动审批后不再发短信
//		else if(type == 2){
//			smstext = "您有未确认工单已超时，工单号"+OrderNo+"，默认确认通过，请查看。";
//		}
		smstext += xcecAddWordsArtStr;
		//短信发送:sprint18更新话术，但app推送不更新
		if(!"".equals(Phone)){
			String reuslt = SmsUtils.sendMessage(Phone, xcecAddWordsArtStr);
			Map<String,Object> map  = getMsgMap(OrderId, xcecAddWordsArtStr, userid, 1, function, category);
			notifyRecordTMapList.add(map);
		}
		if(CollectionUtils.isNotEmpty(notifyRecordTMapList)){
			remindTaskService.saveMsgOperation(notifyRecordTMapList);
		}

		// APP推送
		noticeService.push(function,category,Long.valueOf(OrderId),Long.valueOf(userid),userName,null,smstext,"您有未处理工单",0L);
	}
	
	/**
	 * 消息推送记录
	 * @param OrderId
	 * @param smstext
	 * @param userid
	 * @return
	 */
	public Map<String,Object> getMsgMap(String OrderId,String smstext,String userid,int SendType,int function,int category){
		Map<String, Object> zhuNotifyRecordTMap = new HashMap<String, Object>();
		//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentTime = LocalTimeUtil.getRealCurrentTime();  //获取当前时间
		zhuNotifyRecordTMap.put("OrderId", OrderId);
		zhuNotifyRecordTMap.put("Function", function); 
		zhuNotifyRecordTMap.put("Category", category);  
		zhuNotifyRecordTMap.put("ReceiverId", StringUtils.isEmpty(userid)?null:Long.parseLong(userid));  //接收人
		zhuNotifyRecordTMap.put("Content", smstext);  //消息内容
		zhuNotifyRecordTMap.put("SendType", SendType);   //推送方式1代表短信  2代表app推送
		zhuNotifyRecordTMap.put("SendTime", currentTime);
		zhuNotifyRecordTMap.put("Status", 1);
		zhuNotifyRecordTMap.put("ExceptionInfo", "");
		zhuNotifyRecordTMap.put("IsRead", 0);
		zhuNotifyRecordTMap.put("Flag", 0);
		zhuNotifyRecordTMap.put("Creator", "");
		zhuNotifyRecordTMap.put("CreateTime", currentTime);
		return zhuNotifyRecordTMap;
	}

	private void setOverTimeKey(String orderId,OverTimeType overTimeType){
		Integer code = overTimeType.getCode();
		redisClientUtils.setObject(RedisKeys.overTimeWorkOrderTypeKey(orderId,code), code,60*60*24*30);
	}
}
